package com.bussiness.system.util;

import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author:  xlr
 * @Date: 2018/7/14 18:29
 */
public class Result<T> extends IResult<T> {
    public static final Boolean RESULT_SUCCESS = true;
    public static final Boolean RESULT_FAIL = false;

    private Integer errorCode;
    private String errorMsg;
    private Boolean success = true;


    public Result(T data, Integer errorCode, String errorMsg, Boolean success) {
        super(data);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.success = success;

    }

    public Result(Boolean success, T data) {
        this(data, (Integer) null, (String) null, success);
    }
    public Result(Boolean success, T data,  String errorMsg) {
        this(data, (Integer) null, errorMsg, success);
    }

    public Result(Boolean success) {
        this((T) null, (Integer) null, (String) null, success);
    }

    public Result(Boolean success, Integer errorCode, String errorMsg) {
        this(null, errorCode, errorMsg, success);
    }

    public Result() {
        this(true);
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Boolean isSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    /* 成功返回,无返回数据 */
    public Result<T> success() {
        return new Result(RESULT_SUCCESS);
    }
    public Result<T> error( T data ) {
        return new Result<T>(RESULT_FAIL, data, null);
    }

    public Result<T> error() {
        return new Result<T>(RESULT_FAIL);
    }
    /* 成功返回,有返回数据 */
    public Result<T> success(T data) {
        return new Result<T>(RESULT_SUCCESS, data, null);
    }

    public Result<T> success(T data, String errorMsg) {
        return new Result<T>(RESULT_SUCCESS, data, errorMsg);
    }

    /* 失败返回 */
    public Result<T> fail(int errorCode, String errorMsg) {
        return new Result(RESULT_FAIL, errorCode, errorMsg);
    }
}

